#include "log.h"     
#include <stdio.h>    
#include <time.h>      
#include <stdlib.h>
// 写入日志到log.log文件
void write_log(const char *msg) {
    FILE *fp = fopen("log.log", "a");
    if (!fp) {
        printf("日志文件打开失败！\n");
        return;
    }

    // 获取当前系统时间
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    fprintf(fp, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
            tm->tm_hour, tm->tm_min, tm->tm_sec, msg);
    fclose(fp);
}
